//
//  BBBaseViewModel.m
//  goodsOwner
//
//  Created by apple on 2019/6/28.
//  Copyright © 2019年 fandecai. All rights reserved.
//

#import "BBBaseViewModel.h"

@implementation BBBaseViewModel

- (id)initWithTag:(NSInteger)tag andView:(__kindof UIView *)view
{
    if (self = [super init]) {
        _tag = tag;
        _view = view;
        [view setTag:tag];
    }
    return self;
}

#pragma mark - # Frame
BBKIT_SETPRAGRA_API(frame,CGRect,UIView,BBBaseViewModel *);
BBKIT_SETPRAGRA_API(origin, CGPoint,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(x, CGFloat,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(y, CGFloat,UIView,BBBaseViewModel*);

BBKIT_SETPRAGRA_API(size, CGSize,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(width, CGFloat,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(height, CGFloat,UIView,BBBaseViewModel*);

BBKIT_SETPRAGRA_API(center, CGPoint,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(centerX, CGFloat,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(centerY, CGFloat,UIView,BBBaseViewModel*);

BBKIT_SETPRAGRA_API(top, CGFloat,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(bottom, CGFloat,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(left, CGFloat,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(right, CGFloat,UIView,BBBaseViewModel*);

//- (id (^)(CGRect vframe))frame{
//    @weakify(self);
//    return ^(CGRect vframe){
//        @strongify(self);
//        self.view.frame = vframe;
//        return self;
//    };
//}

#pragma mark - # Color
BBKIT_SETPRAGRA_API(backgroundColor, UIColor *,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(tintColor, UIColor *,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(alpha, CGFloat,UIView,BBBaseViewModel*);


#pragma mark - # Control
BBKIT_SETPRAGRA_API(contentMode, UIViewContentMode,UIView,BBBaseViewModel*);

BBKIT_SETPRAGRA_API(opaque, BOOL,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(hidden, BOOL,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(clipsToBounds, BOOL,UIView,BBBaseViewModel*);

BBKIT_SETPRAGRA_API(userInteractionEnabled, BOOL,UIView,BBBaseViewModel*);
BBKIT_SETPRAGRA_API(multipleTouchEnabled, BOOL,UIView,BBBaseViewModel*);


#pragma mark - # Layout
- (BBBaseViewModel* (^)(void (^constraints)(MASConstraintMaker *make) ))masonry{
  
    return ^(void (^constraints)(MASConstraintMaker *make)){
        if (self.view.superview) {
            [self.view mas_makeConstraints:constraints];
        }
        return  self;
    };
}

- (BBBaseViewModel* (^)(void (^constraints)(MASConstraintMaker *make)))updateMasonry{
    return ^(void (^constraints)(MASConstraintMaker *make) ){
        if (self.view.superview) {
            [self.view mas_updateConstraints:constraints];
        }
        return self;
    };
}

- (BBBaseViewModel* (^)(void (^constraints)(MASConstraintMaker *make)))remakeMasonry{
    return ^(void (^constraints)(MASConstraintMaker *make) ){
        if (self.view.superview) {
            [self.view mas_remakeConstraints:constraints];
        }
        return self;
    };
}


#pragma mark - # Layer
BBKIT_SETPRAGRA_LAYER_API(masksToBounds, BOOL);

- (BBBaseViewModel* (^)(CGFloat cornerRadius))cornerRadius
{
    return ^__kindof BBBaseViewModel *(CGFloat cornerRadius) {
        [self.view.layer setMasksToBounds:YES];
        [self.view.layer setCornerRadius:cornerRadius];
        return self;
    };
}

- (BBBaseViewModel* (^)(CGFloat borderWidth, UIColor *borderColor))border
{
    return ^__kindof BBBaseViewModel *(CGFloat borderWidth, UIColor *borderColor) {
        [self.view.layer setBorderWidth:borderWidth];
        [self.view.layer setBorderColor:borderColor.CGColor];
        return self;
    };
}
BBKIT_SETPRAGRA_LAYER_API(borderWidth, CGFloat);
BBKIT_SETPRAGRA_LAYER_API(borderColor, CGColorRef);

BBKIT_SETPRAGRA_LAYER_API(zPosition, CGFloat);
BBKIT_SETPRAGRA_LAYER_API(anchorPoint, CGPoint);

- (BBBaseViewModel* (^)(CGSize shadowOffset, CGFloat shadowRadius, UIColor *shadowColor, CGFloat shadowOpacity))shadow
{
    return ^__kindof BBBaseViewModel *(CGSize shadowOffset, CGFloat shadowRadius, UIColor *shadowColor, CGFloat shadowOpacity) {
        [self.view.layer setShadowOffset:shadowOffset];
        [self.view.layer setShadowRadius:shadowRadius];
        [self.view.layer setShadowColor:shadowColor.CGColor];
        [self.view.layer setShadowOpacity:shadowOpacity];
        return self;
    };
}
BBKIT_SETPRAGRA_LAYER_API(shadowColor, CGColorRef);
BBKIT_SETPRAGRA_LAYER_API(shadowOpacity, CGFloat);
BBKIT_SETPRAGRA_LAYER_API(shadowOffset, CGSize);
BBKIT_SETPRAGRA_LAYER_API(shadowRadius, CGFloat);
BBKIT_SETPRAGRA_LAYER_API(transform, CATransform3D);

@end
